var fs = require('fs');

// 读取文件
var re = fs.createReadStream('./a.txt', 'utf-8')

re.on('data', function (chunk) {
    console.log('read file');
    console.log(chunk);
});

re.on('end', function () {
    console.log('读取完毕');
})

re.on('error', function (err) {
    console.log('Error:' + error)
})

console.log('这里是同步输出')

// 写入文件
var wf = fs.createWriteStream('./write.txt', 'utf-8')

wf.write('line one]\n', (error) => {
    if (error) {
        console.log('write failed');
    } else {
        console.log('write success');
    }
})

wf.write('line tow\n', (error) => {
    if (error) {
        console.log('write failed');
    } else {
        console.log('write success');
    }
})
wf.end()